package com.itheima.domain;

import com.alibaba.druid.pool.DruidDataSource;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.sql.Connection;
import java.sql.SQLException;

public class DemoDataSource {
    @Test
    public void testDruid() throws Exception {
        //创建数据库连接池对象
        DruidDataSource ds = new DruidDataSource();
        //设置四大特征
        ds.setDriverClassName("com.mysql.jdbc.Driver");
        ds.setUrl("jdbc:mysql://127.0.0.1:3306/db1");
        ds.setUsername("root");
        ds.setPassword("root");

        Connection co = ds.getConnection();
        System.out.println(co);
    }

    @Test
    public void test02() throws SQLException {
        ApplicationContext is = new ClassPathXmlApplicationContext("springSql.xml");
        DruidDataSource ds = is.getBean(DruidDataSource.class);

        Connection co = ds.getConnection();
        System.out.println(co);
    }
}
